#include "./progress_bar.h"
#include <QPainter>
#include <QDebug>

ProgressBar::ProgressBar(QWidget *parent) : QWidget(parent) {
    progress();
}

void ProgressBar::timerEvent(QTimerEvent *event) {
    m_prog += 2;
    update();
}

void ProgressBar::paintEvent(QPaintEvent *event) {
    Q_UNUSED(event);
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    int prog = m_prog % 101;
    int w = width();
    int h = height();
    int d = w;
    if (h < w) {
        d = h;
    }
    int MARGIN = d * 0.13;
    int r = d / 2 - MARGIN / 2;
    QRectF rect(-r, -r, 2 * r, 2 * r);
    painter.translate(w / 2, h / 2);

    switch (m_type) {

        case Type::SUCC: painter.drawImage(rect, QImage(":/ic_succ.png")); return;
        case Type::ERR: painter.drawImage(rect, QImage(":/ic_err.png")); return;
        case Type::WARN: painter.drawImage(rect, QImage(":/ic_warn.png")); return;
    }

    QPen p(Qt::blue, MARGIN);
    p.setCapStyle(Qt::PenCapStyle::RoundCap);
    p.setJoinStyle(Qt::PenJoinStyle::RoundJoin);
   // painter.drawEllipse(rect);
    

    int c = 360 * prog / 100;
   // painter.rotate( c );

    painter.setPen(p);
   // painter.setBrush(Qt::blue);
    painter.drawArc(rect, c * 16, c * 16);
}




